<template>
  <div>
    <el-card>
      <div class="header">
              <el-button
        type="primary"
        @click="handleAdd"
      >添加名片背景
      </el-button>
      </div>

      <el-table
        :data="tableData"
        style="width:100%;margin-top: 30px;"
        align="center"
      >
        <el-table-column
          prop="name"
          label="名称"
          align="center"
        >
        </el-table-column>

        <el-table-column
          prop="img"
          label="样式-背景"
        >
          <template slot-scope="scope">
            <el-image
              v-if="scope.row.img!==null"
              style="width: 50px;height: 50px"
              :src="scope.row.img"
              fit="contain"
            >
            </el-image>
            <span v-else>无</span>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.tenantId!=='0'"
              size="mini"
              type="primary"
              @click="Edit(scope.row)"
            >编辑
            </el-button>
            <el-button
              v-if="scope.row.tenantId!=='0'"
              size="mini"
              type="danger"
              @click="Delete(scope.row.id)"
            >删除
            </el-button>
            <span v-else>系统默认选项，无法操作</span>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <create
      ref="create"
      @Ok="handleInit"
    ></create>
    <edit ref="edit" @Ok="handleInit"></edit>
  </div>
</template>

<script>
  import {cardStyleList, removeStyle} from "@/api/set";

  import Create from "./components/create";
  import Edit from "./components/edit";

  export default {
    name: "index",
    components: {
      Create,
      Edit
    },
    data() {
      return {
        value: '',
        tableData: [],
        page: 1,
        size: 10,
        total: 1,
        id: '',

      }
    },
    mounted() {
      this.handleInit()
    },
    methods: {
      handleInit() {
        cardStyleList().then(res => {
          this.tableData = res.result
          this.total = Number(res.result.total)
        })
      },
      handleAdd() {
        this.$refs['create'].show()
      },

      handleNext(e) {
        this.page = e
        this.handleInit()
      },
      Edit(data) {
        this.$refs['edit'].show(data)
      },
      Delete(id) {
        this.id = id
        let form = {
          id: this.id
        }
        removeStyle(form).then(res => {
          if (res.status == 200) {
            this.$message.success('删除成功');
            this.handleInit()

          }
        })
      },
    }
  }
</script>
<style scoped>
  .header {
     width: 100%;
    display: flex;
    justify-content: flex-end;
  }
</style>
